﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AnalysisServices;

namespace ASPermissions
{
    class Permission
    {
        static void Main(string[] args)
        {
            try
            {
                Arguments CommandLine = new Arguments(args);

                if (CommandLine["?"] != null || args.Length == 0 || CommandLine["s"] == null || CommandLine["d"] == null)
                {
                    Console.WriteLine("*** Analysis Services Permissions (aspermissions.exe) - V1.0 by Rodrigo Souza (rsouza)");
                    Console.WriteLine("Usage: /s:[Servername\\Instance] and /d:[Database name]");
                    return;
                }
                else
                {
                    Console.WriteLine("*** Analysis Services Permissions (aspermissions.exe) - V1.0 by Rodrigo Souza (rsouza)");
                    Console.WriteLine("");

                    Amo amo = new Amo(CommandLine["s"], CommandLine["d"]); //@"RSOUZA-MSFT2\SQL2008R2", "Adventure Works DW 2008R2");//, "Adventure Works");
                    int i = amo.ListAllRolesAndMembers();

                    Console.WriteLine("");
                    Console.WriteLine("Number of Roles: {0}", i.ToString());
                }
            }
            catch (Exception Except)
            {
                throw new Exception("Error Parsing command..." + Except.Message);
            }
        }
    }
}
